/**
 * @description 获取树形结构指定节点下的所有叶子节点
 * @param {Object} node 树节点
 */
interface NodeConfig {
	idField?: string;
	childrenField?: string;
	leafField?: string;
}

interface TreeNode {
	[key: string]: any;
}

const getLeafNodes = function (node: TreeNode, config: NodeConfig = {}): TreeNode[] {
	if (!node) {
		console.error('提供的节点为空，无法进行搜索。');
		return [];
	}
	const currentConfig = {
		...{
			idField: 'id',
			childrenField: 'childrens',
			leafField: 'isCamera',
		},
		...config,
	};
	const leafNodes: TreeNode[] = [];
	function recursiveSearch(node: TreeNode) {
		if (node[currentConfig.leafField] === 1 && node[currentConfig.idField]) {
			leafNodes.push(node);
		}
	}

	return leafNodes;
};
export default getLeafNodes;
